<template>
  <div>
     <!-- 新建组织对话框 -->
          <!-- @childFn='parentFn'(父亲接收子传递过来的值) :hiddens='dialogVisible'(子向父传递参数) -->
        <dialogIndex @childFn='parentFn' :hiddens='dialogVisible'>
          <el-form :rules="formrules" ref="formrules" :model="infeform" label-width="80px">
            <el-form-item label="组织名称" prop="title">
                <el-input v-model="infeform.title"></el-input>
            </el-form-item>
            <el-form-item label="节点类型" prop="nodeTypes">
                <el-input v-model="infeform.nodeTypes"></el-input>
            </el-form-item>
          </el-form>
        </dialogIndex>
  </div>
</template>

<script>
import dialogIndex from '@/components/commons/Dialog/index.vue'
export default {
  name: 'componentForm',
  components:{
    dialogIndex
  },
  data(){
      return{
          // 对话框的基本内容
        dialogVisible:{},
        infeform:{
            title:'',
            nodeTypes:'',
        },
        formrules:{
            title: [
                { required: true, message: '请输入用户名', trigger: 'blur' }
            ],
            nodeTypes: [
                { required: true, message: '请输入密码', trigger: 'blur' }
            ]
        },
      }
  },
  methods:{
      // 关闭并重置表单
      refsClose(){
          this.$refs.formrules.resetFields()
      },
      // 接收子组件传递的值
      parentFn(val){
          if(val=='sub'){
              this.$refs.formrules.validate((valid) => {
                  if(!valid) return;
                  this.$message.success('保存');
                  this.refsClose();
                  this.dialogVisible.okForm=false
              })
              // 重置表单
          }else if(val=='hidden' || val=='close'){
              this.refsClose()
          }
      },
  }
}
</script>

<style lang="less" scoped>
</style>
